package org.shopen.ai.puremvc.model.problem.cities
{
	import mx.collections.ArrayCollection;
	
	import org.shopen.ai.puremvc.model.problem.IAction;
	import org.shopen.ai.puremvc.model.problem.IState;
	import org.shopen.ai.puremvc.model.problem.ITransitionModel;
	import org.un.cava.birdeye.ravis.graphLayout.data.IEdge;
	import org.un.cava.birdeye.ravis.graphLayout.data.IGraph;
	import org.un.cava.birdeye.ravis.graphLayout.data.INode;
	
	public class TransitionModel implements ITransitionModel
	{		
		protected var graph : IGraph;
		protected var title : String = "unknown transition model";
		
		public function TransitionModel(graph : IGraph, title : String = "unknown")
		{
			this.graph = graph;
		}
		
		public function buildActions(state : IState) : ArrayCollection
		{
			var result : ArrayCollection;
			var node : INode = (state as INode);
			for each (var edge : IEdge in node.outEdges)
			{
				result.addItem(edge.toNode);
			}
			return result;
		}
		
		public function performAction(state : IState, action : IAction) : IState
		{
			// GoAction completely determines next state.
			var result : IState = action.act();
			return result;
		}
		
		public function toString() : String
		{
			return title;
		}
		
	}
}